package com.bjpowernode.boss.web.controller;

import com.bjpowernode.boss.common.enums.AjaxCode;
import com.bjpowernode.boss.convert.PayConvert;
import com.bjpowernode.boss.db.domain.PayProduct;
import com.bjpowernode.boss.web.service.PayProductService;
import com.bjpowernode.boss.web.models.form.ProductForm;
import com.bjpowernode.boss.web.models.result.AjaxResult;
import com.bjpowernode.boss.web.models.vo.PayProductVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 产器控制层
 *
 * @author shenlang
 * @date 2024-06-02 21:20
 * @version  1.0.0
 * TODO 添加描述
 */
@Controller
@ResponseBody
public class ProductController {
    @Resource
    private PayConvert payConvert;
    @Resource
    private PayProductService payProductService;
    /**
     * 获取支付产品信息
     * @return com.bjpowernode.boss.web.models.result.AjaxResult
     * @date 2024-06-03 17:15:27 17:15
     */
    @RequestMapping("/product/getProductTable")
    public AjaxResult getProductTable(){
        List<PayProduct> payProducts = payProductService.getAllProducts();
        List<PayProductVo> payProductVos = payConvert.toPayProductVos(payProducts);
        return new AjaxResult(AjaxCode.PAY_PRODUCT_GET_SUCCESS,payProductVos);
    }
    /**
     * 添加支付产品
     *
     * @param productForm 添加的产品数据
     * @return com.bjpowernode.boss.web.models.result.AjaxResult
     * @date 2024-06-03 19:00:10 19:00
     */
    @RequestMapping("/product/addProduct")
    public AjaxResult addProduct(@RequestBody PayProduct productForm){
        boolean bool = payProductService.addProduct(productForm);
        return new AjaxResult(AjaxCode.ADD__SUCCESS,bool);
    }
    /**
     * 编辑支付产品状态
     *
     * @param id 支付产品id
     * @param status 支付产品状态
     * @return com.bjpowernode.boss.web.models.result.AjaxResult
     * @date 2024-06-03 20:18:49 20:18
     */
    @RequestMapping("/product/changeStatus")
    public AjaxResult changeStatus(@RequestParam String id,@RequestParam String status){
        boolean bool = payProductService.changeStatus(id,status);
        return new AjaxResult(AjaxCode.CHANGE_STATUS_SUCCESS,bool);
    }
    /**
     * 编辑支付产品
     *
     * @param productForm 产品信息
     * @return com.bjpowernode.boss.web.models.result.AjaxResult
     * @date 2024-06-03 21:15:46 21:15
     */
    @RequestMapping("/product/editProduct")
    public AjaxResult editProduct(@RequestBody ProductForm productForm){
        boolean bool = payProductService.editProduct(productForm);
        return new AjaxResult(AjaxCode.EDIT__SUCCESS,bool);
    }
    /**
     * 删除支付产品
     *
     * @param id 产品id
     * @return com.bjpowernode.boss.web.models.result.AjaxResult
     * @date 2024-06-03 21:23:08 21:23
     */
    @RequestMapping("/product/singleDeleteProduct")
    public AjaxResult singleDeleteProduct(@RequestParam String id){
        boolean bool = payProductService.singleDelete(id);
        return new AjaxResult(AjaxCode.DELETE__SUCCESS,bool);
    }
    /**
     * 批量删除
     *
     * @param ids id集合
     * @return com.bjpowernode.boss.web.models.result.AjaxResult
     * @date 2024-06-03 21:47:33 21:47
     */
    @RequestMapping("/product/batchDeleteProduct")
    public AjaxResult batchDeleteProduct(@RequestParam List<String> ids){
        boolean bool = payProductService.batchDelete(ids);
        return new AjaxResult(AjaxCode.DELETE__SUCCESS,bool);
    }
}
